//
//  SendScoreViewController.m
//  ToucheTouche
//
//  Created by polytech polytech on 19/01/12.
//  Copyright (c) 2012 polytech. All rights reserved.
//

#import "SendScoreViewController.h"
#import "ScoresList.h"

@implementation SendScoreViewController
@synthesize buttonSend;
@synthesize textFieldInfo;
@synthesize textFieldNickname;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
   [super viewDidLoad];
    [textFieldInfo setText:[NSString stringWithFormat:@"Bravo vous avez fait un nouveau score de %d !", [[ScoresList sharedScoresList] getScore]]]; 
    
}

- (void)viewDidUnload
{
    [self setTextFieldNickname:nil];
    [self setButtonSend:nil];
    [self setTextFieldInfo:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (IBAction)sendScore:(id)sender
{
    if([[ScoresList sharedScoresList] addNickname:[textFieldNickname text]]) {
        UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Score ajouté" message:@"Score ajouté avec succés !" delegate:self cancelButtonTitle:nil otherButtonTitles:nil] autorelease];
        [alertView addButtonWithTitle:@"OK"];
        [alertView show];
        [self setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [self dismissModalViewControllerAnimated:YES];
    } else {
        UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Erreur ajout score" message:@"Erreur lors de l'ajout du score !" delegate:self cancelButtonTitle:nil otherButtonTitles:nil] autorelease];
        [alertView addButtonWithTitle:@"OK"];
        [alertView show];
        [self setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [self dismissModalViewControllerAnimated:YES];
    }
    [sender resignFirstResponder];
}

- (void)dealloc {
    [textFieldNickname release];
    [buttonSend release];
    [textFieldInfo release];
    [super dealloc];
}
@end
